<?php
namespace backend\models\activeRecords;

use Yii;
use yii\db\ActiveRecord;

/**
 * This is the model class for table "{{%t_user}}".
 *
 * @property string $id 用户id
 * @property string $username 用户名(登陆帐号)
 * @property string $auth_key
 * @property string $password_hash
 * @property string $password_reset_token
 * @property string $avatar 头像
 * @property string $email 邮箱
 * @property int $status 状态(1正常)
 * @property string $register_time 注册时间
 * @property string $join_ip 注册ip
 * @property string $last_login_time 最后登陆时间
 * @property string $spread_key_1 父渠道ID
 * @property string $spread_key_2 子渠道ID
 * @property string $reg_game_id 注册游戏ID
 * @property string $reg_game_name 注册游戏名称
 * @property string $reg_server_id 注册区服ID
 * @property string $reg_server_name 注册区服名称
 * @property string $spread_key 所属父类
 * @property int $is_deducted 是否被扣量
 */
class TUser extends ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%t_user}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['username','spread_key_2', 'reg_game_name', 'reg_server_name', 'reg_game_id', 'reg_server_id','password_hash'], 'required'],
            [['status', 'register_time', 'last_login_time', 'reg_game_id', 'reg_server_id', 'is_deducted'], 'integer'],
            [['username', 'password_hash', 'password_reset_token', 'avatar', 'email', 'join_ip', 'reg_game_name', 'reg_server_name'], 'string', 'max' => 255],
            [['auth_key'], 'string', 'max' => 32],
            [['spread_key_1', 'spread_key_2', 'spread_key'], 'string', 'max' => 50],
            [['username'], 'unique'],
        ];
    }


    public function scenarios()
    {
        $config = parent::scenarios(); // TODO: Change the autogenerated stub
        $config['default'] = ['password_hash'];
        $config['binding'] = ['username','spread_key_2', 'reg_game_name', 'reg_server_name', 'reg_game_id', 'reg_server_id'];
        return $config;
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', '用户id'),
            'username' => Yii::t('app', '用户名(登陆帐号)'),
            'auth_key' => Yii::t('app', 'Auth Key'),
            'password_hash' => Yii::t('app', 'Password Hash'),
            'password_reset_token' => Yii::t('app', 'Password Reset Token'),
            'avatar' => Yii::t('app', '头像'),
            'email' => Yii::t('app', '邮箱'),
            'status' => Yii::t('app', '状态(1正常)'),
            'register_time' => Yii::t('app', '注册时间'),
            'join_ip' => Yii::t('app', '注册ip'),
            'last_login_time' => Yii::t('app', '最后登陆时间'),
//            'spread_key_1' => Yii::t('app', '父渠道ID'),
            'spread_key_2' => Yii::t('app', '所属员工'),
            'reg_game_id' => Yii::t('app', '注册游戏ID'),
            'reg_game_name' => Yii::t('app', '注册游戏名称'),
            'reg_server_id' => Yii::t('app', '注册区服ID'),
            'reg_server_name' => Yii::t('app', '注册区服名称'),
            'spread_key' => Yii::t('app', '公会'),
            'is_deducted' => Yii::t('app', '是否被扣量'),
        ];
    }

    public function getGame(){
        return $this->hasOne(TGame::className(),['game_id'=>'reg_game_id']);
    }

    public function getServer(){
        return $this->hasOne(TServer::className(),['server_id'=>'reg_server_id']);
    }


}
